const app = getApp();

// pages/mine/address.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    tel: '',
    address: '',
    region: ['上海市', '上海市', '黄埔区'],
    tag:['家','公司','学校'],
    currentTab:2,
    inputValue:'',
    hiddenmodalput: true,
  },
  
  //响应点击导航栏
  tagTap: function (e) {
    var that = this;
    that.setData({
      currentTab: e.currentTarget.dataset.idx,
      TypeItem: that.data.tag[that.data.currentTab]
    })
  },

  //点击按钮痰喘指定的hiddenmodalput弹出框  
  modalinput: function () {
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput
    })
  },
  //取消按钮  
  cancel: function () {
    this.setData({
      hiddenmodalput: true
    });
  },
  //确认  
  confirm: function () {
    var that = this;
    var tag = that.data.tag;
    tag.push(that.data.inputValue);
    that.setData({
      tag: tag,
      hiddenmodalput: true
    })
  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },

  deleteTagTap:function(e){
    var that = this;
    var tag = that.data.tag;
    var index = e.currentTarget.dataset.idx;
    console.log(index);
    wx.showModal({
      title: '提示',
      content: '确定删除标签',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          Array.prototype.delete = function (delIndex) {
            var temArray = [];
            for (var i = 0; i < this.length; i++) {
              if (i != delIndex) {
                temArray.push(this[i]);
              }
            }
            return temArray;
          }

          tag.delete(index);
          that.setData({
            tag: tag,
            hiddenmodalput: true
          })
          tag.push(that.data.inputValue);
          that.setData({
            tag: tag,
            hiddenmodalput: true
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var addressId = options.addressId
    console.log(addressId);
  },
  //姓名
  nameInput: function() {
    this.setData({
      name: e.detail.value
    })
  },
  //手机号码
  telInput: function() {
    this.setData({
      tel: e.detail.value
    })
  },
  //详细地址
  addressInput: function() {
    this.setData({
      address: e.detail.value
    })
  },
  //添加收货地址
  address: function() {
    app.wxPost(app.globalData.host + '/info/delAddress', {
      name: name,
      province: province,
      city: city,
      district: district,
      address: address,
      tel: tel,
      is_default: is_default,
      tip: tip
    }).then(res => {
      console.log(res)
    })
  },

  bindRegionChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },
})